package com.polaris.live.im.sfs.processor.impl

import com.polaris.live.common.manager.CoroutineScopeManager
import com.polaris.live.common.util.JsonUtils
import com.polaris.live.common.util.ViewUtils
import com.polaris.live.im.sfs.COMMAND_NOTICE_POPUP
import com.polaris.live.im.sfs.bean.pusher.PusherNoticeMessage
import com.polaris.live.im.sfs.bean.pusher.UserPopupNoticeMessage
import com.polaris.live.im.sfs.core.bean.DataArgument
import com.polaris.live.im.sfs.processor.AbstractMessageProcessor
import com.polaris.live.popup.WeeklyStarRewardPopup
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 * NoticeTaskMessageProcessor
 *
 * @author Created by 半仙 on 2024/3/13/013 10:57
 */
class NoticePopMessageProcessor : AbstractMessageProcessor() {

    override fun shouldProcess(type: Int, command: String): Boolean {
        return command == COMMAND_NOTICE_POPUP
    }

    override suspend fun handle(type: Int, command: String, argument: DataArgument) {
        val data = argument.getData<PusherNoticeMessage>() ?: return
        val message = JsonUtils.fromJson<UserPopupNoticeMessage>(data.content) ?: return
        withContext(CoroutineScopeManager.mainDispatcher) {
            val aliveTopActivity = ViewUtils.getAliveTopActivity() ?: return@withContext
            when (message.templateType) {
                1 -> { //1: 通用模板1
                    CoroutineScopeManager.mainScope.launch {
                        WeeklyStarRewardPopup.showPop(aliveTopActivity, message)
                    }
                }

            }

        }
    }
}